home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / dbms_mag / 9103 / techtip1.mar < prev    next >
Text File  |  1991-01-30  |  1KB  |  48 lines

  1.  
  2. Listing 1 (Darling, March)
  3.  
  4.  
  5. REM PickSort. SQL
  6. REM User-selectable sort orders in ORACLE's SQL*Plus
  7.  
  8. REM Charles B. Darling
  9. REM Better Business Solutions, Inc. Clearwater, FL
  10.  
  11. REM   Since SQL*Plus can't loop, the menu is necessarily pretty crude:
  12.  
  13. PROMPT 1. Name
  14. PROMPT 2. Mail Stop
  15. PROMPT 3. ZIP Code
  16. PROMPT
  17. ACCEPT Choice NUMBER PROMPT 'What order would like the list in?'
  18.  
  19. REM    Print the list per the user's chioce:
  20.  
  21. SELECT FirstName, LastName, MailStop, ZIP
  22. FROM Members
  23. ORDER BY DECODE(&Choice, 1, LastName, 2, MailStop, 3, ZIP);
  24.  
  25. REM    You can also do compound sorts:
  26.  
  27. PROMPT 1. Last Name, First Name
  28. PROMPT 2. Mail Stop, Last Name
  29. PROMPT 3. ZIP Code, Mail Stop, Last Name
  30. PROMPT
  31. ACCEPT Choice NUMBER PROMPT 'What order would you like the list in? ' 
  32.  
  33. REM    Print the list per the user's choice:
  34.  
  35. SELECT FirstName, LastName, MailStop, ZIP
  36. FROM Members
  37. ORDER BY DECODE(&Choice, 1, LastName, 2, MailStop, 3, Zip),
  38.          DECODE(&Choice, 1, FirstName 2, LastName, 3, MailStop),
  39.          DECODE(&Choice, 1, '',       2, '',       3, LastName);
  40.  
  41. REM   Though using the concatenation operator is more efficient:
  42.  
  43. SELECT FirstName, LastName, MailStop, ZIP
  44. FROM Members
  45. ORDER By DECODE(&Choice, 1, LastName::FirstName,
  46.              2, MailStop::LastName,
  47.              3, ZIP::MailStop::LastName);~~~~~
  48.